package itheima.com.Demo01.demo01.getsum;

public class Student implements Comparable<Student> {
    private String name;
    private int chinese;
    private int math;
    private int englis;

    public Student() {
    }

    public Student(String name, int chinese, int math, int englis) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.englis = englis;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglis() {
        return englis;
    }

    public void setEnglis(int englis) {
        this.englis = englis;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", englis=" + englis +
                '}'+"总分："+sum();
    }

    public int sum() {
        return chinese + math + englis;
    }

    @Override
    public int compareTo(Student o) {
        int i = this.sum() - o.sum();
        i = i == 0 ? this.getChinese() - o.getChinese() : i;
        i = i == 0 ? this.getMath() - o.getMath() : i;
        i = i == 0 ? this.getEnglis() - o.getEnglis() : i;
        i = i == 0 ? this.getName().compareTo(o.getName()) : i;
        return i;
    }
}
